//
//  ViewController.m
//  TestIJK_OC
//
//  Created by DaveYou on 2021/7/30.
//

#import "ViewController.h"
#import <IJKMediaFramework/IJKMediaFramework.h>
@interface ViewController ()
@property (atomic, retain) id <IJKMediaPlayback> player;
@property (weak, nonatomic) IBOutlet UIView *playView;
@property (weak, nonatomic) IBOutlet UIButton *playBtn;
@end

@implementation ViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (![_player isPlaying]) {
        [self.player prepareToPlay];
    }
}
-(void)viewDidLoad {
    [super viewDidLoad];
    
    NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"];

    _player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:nil];
    UIView *playerView = [_player view];
    playerView.frame = self.playView.frame;
    [self.view addSubview:playerView];
}
-(IBAction)clickedAction:(id)sender {
    if (![_player isPlaying]) {
        [self.player play];
        [self.playBtn setTitle:@"Pause" forState:UIControlStateNormal];
    }else {
        [self.player pause];
        [self.playBtn setTitle:@"Play" forState:UIControlStateNormal];
    }
}

@end
